<template>
    <div class="video-check">
            <nav-header></nav-header>
            <div class="zh-table">
                <div class="zh-table-open clear">
                    <div class="zh-open-left fl">
                        <!-- 如果是学校教育局 this.$store.state.platformInformation = true -->
                        <div class="open-width" style="width: 150px" v-if="$store.state.platformInformation">
                            <el-select v-model="school_id" filterable placeholder="教育局/学校">
                                <el-option
                                    v-for="item in schoolcodeData"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </div>
                        <div class="open-width" v-else>
                            <el-select v-model="platform_id" filterable placeholder="来源学校/教育局">
                                <el-option
                                    v-for="item in platformList"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item.id">
                                </el-option>
                            </el-select>
                        </div>
                        <div class="open-width" style="width: 120px" v-if="$store.state.platformInformation">
                            <el-select v-model="status" filterable placeholder="选择状态">
                                <el-option label="待审核" :value="1"></el-option>
                                <el-option label="已通过" :value="2"></el-option>
                                <el-option label="已拒绝" :value="3"></el-option>
                            </el-select>
                        </div>
                        <div class="open-width">
                            <el-input placeholder="视频名称、教师名称" v-model="keyword" @keyup.enter.native="search"></el-input>
                        </div>
                        <el-button type="primary" @click="search">搜索</el-button>
                        <el-button type="primary" @click="reset">重置</el-button>
                    </div>
                    <div class="zh-open-right fr">
                        <el-button type="danger" @click="deleteAll">批量删除</el-button>
                    </div>
                </div>
                <div class="zh-table-contents" v-loading="loading.status" :element-loading-text="loading.txt">
                    <el-table
                        v-if="$store.state.checkLevel"
                        :data="listData"
                        border
                        @selection-change="tableSelectionChange"
                        max-height="541"
                        style="width: 100%">          
                        <el-table-column
                        fixed
                        type="selection"
                        width="50"
                        align="center"
                        >
                        </el-table-column>
                        <el-table-column
                        prop="name"
                        label="视频名"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                         <el-table-column
                        prop="videoInfo.category"
                        label="组织架构"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        prop="videoInfo.teacher_name"
                        label="教师"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        width="100"
                        prop="videoInfo.size"
                        label="大小"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        prop="push_time"
                        label="推送时间"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        width="100"
                        prop="status_txt"
                        label="状态"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        fixed="right"
                        prop="handle"
                        label="操作"
                        align="center"
                        width="300"
                        >
                        <template slot-scope="scope">
                            <!-- <el-button v-if="scope.row.status_txt === '已通过'" @click.stop="videoEdit(scope.row)" type="text">编辑</el-button> -->
                            <el-button v-if="scope.row.status_txt === '待审核'" @click.stop="videoView(scope.row)" type="text">预览</el-button>
                            <el-button v-if="scope.row.status_txt === '待审核'" @click.stop="videoPassTrigger(scope.row)" type="text">通过</el-button>
                            <el-button v-if="scope.row.status_txt === '待审核'" @click.stop="rejectTrigger(scope.row)" class="delete-button" type="text">拒绝</el-button>
                            <!-- <el-button v-if="scope.row.status_txt === '已通过'" @click.stop="down(scope.row.new_res_id)" type="text">下载</el-button> -->
                            <!-- <el-button v-if="scope.row.status_txt === '已通过'" @click.stop="pushIndexBox(scope.row)" type="text">推首页</el-button> -->
                            <!-- <el-button v-if="scope.row.status_txt === '已通过'" @click.stop="pushUpTrigger(scope.row)" type="text">推上级</el-button> -->
                            <el-button v-if="scope.row.status_txt === '已拒绝' || scope.row.status_txt === '已通过'" type="text" class="delete-button" @click.stop="delTrigger(scope.row)">删除</el-button>
                        </template>
                        </el-table-column>
                    </el-table>
                    <el-table
                        v-else
                        :data="listData"
                        border
                        max-height="541"
                        >          
                        <el-table-column
                            type="index"
                        label="序号"
                        align="center"
                            width="50"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        prop="source_name"
                        label="来源"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        prop="res_name"
                        label="视频名称"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        prop="category"
                        label="视频分类"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        prop="teacher_name"
                        label="教师"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        prop="res_type_name"
                        label="视频信息"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        prop="push_time"
                        label="上传时间"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        prop="size"
                        label="大小"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        prop="status_name"
                        label="审核状态"
                        align="center"
                        show-overflow-tooltip
                        >
                        </el-table-column>
                        <el-table-column
                        fixed="right"
                        prop="handle"
                        label="操作"
                        align="center"
                        width="250"
                        >
                        <template slot-scope="scope">
                            <el-button @click="videoView(scope.row)" type="text">预览</el-button>
                            <el-button v-if="scope.row.status === 1" type="text" @click="passTrigger(scope.row)">批准</el-button>
                            <el-button v-if="scope.row.status === 1" type="text" @click="rejectTrigger(scope.row)">拒绝</el-button>
                            <el-button v-if="scope.row.status === 3" type="text" @click="checkReject(scope.row)">拒绝理由</el-button>
                            <el-button v-if="scope.row.status !== 1" type="text" class="delete-button" @click="delTrigger(scope.row)">删除</el-button>
                        </template>
                        </el-table-column>
                    </el-table>
                    <div class="table-pagination" v-show="total_number > 10">
                        <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="listParam.page_index"
                            :page-sizes="[10, 20, 30, 40, 50, 100]"
                            :page-size="listParam.page_size"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="total_number">
                        </el-pagination>
                    </div>
                </div>
        </div>
        <!-- 视频预览begin -->
        <transition name="el-fade-in-linear" >
            <div class="masking" :class="{ activeLive: isActive }">
                <div class="maskingBox">
                    <div class="masking_h">
                        <span>视频预览</span>
                        <i class="el-icon-close" @click="viewClose"></i>
                    </div>
                    <div class="masking_c">
                        <!-- <nativeVideo  v-if="showVideoPlayer" :playParam.sync="playParam" ></nativeVideo> -->
                        <videoAlertView  v-if="showVideoPlayer" :playParam.sync="playParam"></videoAlertView>
                    </div>
                </div>
            </div>
        </transition>
        <!-- bengin -->
        <el-dialog
        title="拒绝"
        :visible.sync="rejectDescFlag"
        :close-on-click-modal="false" 
        :close-on-press-escape="false"
        width="40%"
        >
        <div v-text="rejectDesc"></div>
        <span slot="footer" class="dialog-footer">
            <el-button @click="rejectDescFlag = false">取 消</el-button>
            <el-button type="primary" @click="rejectDescFlag = false">确 定</el-button>
        </span>
        </el-dialog>
        <!-- 拒绝理由end -->
        <!-- 拒绝bengin -->
        <el-dialog
        title="审核拒绝"
        :visible.sync="rejectWin"
        :close-on-click-modal="false" 
        :close-on-press-escape="false"
        width="33%"
        >
        <div style="text-align: center; margin: 15px 0 20px 0;">是否拒绝该视频的推送？</div>
        <!-- <div class="textarea-box">
            <el-form :model="rejectForm"  ref="rejectForm" label-width="80px" class="demo-ruleForm">
            <el-form-item label="拒绝理由" prop="txt" :rules="[{required: true,message: '请填写拒绝理由',validator: checkValue}]">
                <el-input type="textarea" placeholder="在此填写拒绝理由..." v-model="rejectForm.txt" :maxlength="100" required></el-input>
            </el-form-item>
            </el-form>
            <p class="str-num"><span v-text="rejectForm.txt.length"></span>/<span class="str-max">100</span></p>
        </div> -->
        <span slot="footer" class="dialog-footer">
            <el-button @click="rejectWinHide">取 消</el-button>
            <el-button type="primary" @click="reject">确 定</el-button>
        </span>
        </el-dialog>
        <!-- 拒绝end -->
        <!-- 推首页 -->
		<el-dialog
			title="首页展示"
			:visible.sync="homeVisible"
			width="800px"
			custom-class="home-page"
			:close-on-click-modal="false">
			<div class="home-page-c">
				<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
					<el-form-item label-width="0" prop="selectIndex">
						<el-radio-group v-model="ruleForm.selectIndex">
							<el-radio v-for="(item,inx) in positionData" @change="renderPushHtml()" :key="inx" :label="inx" class="page-checked">
								<div class="home-page-ls">
									<div>
										<img :src="BASE_URL+item.picture" > 
										<i class="el-icon-error" v-if="parseInt(item.id) > 0 && parseInt(pushObj.resid) != parseInt(item.resid) " @click.prevent="deletePushIndex(inx)"></i>

									</div>
									<p>位置{{inx+1}}</p>
								</div>
							</el-radio>
						</el-radio-group>

					</el-form-item>
					<el-form-item label-width="0" style="padding-bottom: 20px">
						<el-button @click="pushToTop()">首页置顶</el-button>
						<el-button @click="resetForm('ruleForm')" type="primary" plain>重置</el-button>
					   <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
					  
					 </el-form-item>
				</el-form>
			</div>
		</el-dialog>
        <!-- 推首页 -->
        <!-- 推上级start -->
		<el-dialog
        title="推上级"
        :visible.sync="pushUpFlag"
        :close-on-click-modal="false" 
        :close-on-press-escape="false"
        width="40%"
        >
            <span style="padding-left: 10px;display: block;margin-bottom: 30px;">推送的视频需要上级审核才能通过展示，是否确认将{{ videoForm.video_name }}推送到上级教育局平台？</span>
            <span slot="footer" class="dialog-footer">
                <el-button @click="pushUpTips()">取 消</el-button>
                <el-button type="primary" @click="pushUpTips(1)">确 定</el-button>
            </span>
        </el-dialog>
		<!-- 推上级end -->

        <el-dialog
            title="审核通过"
            :visible.sync="videoPassFlag"
            :close-on-click-modal="false" 
            :close-on-press-escape="false"
            width="33%">
		    <el-form :model="videoPassForm" ref="videoPassForm" label-width="80px"> 
                <p style="padding-left: 14px;">请对通过审核的资源进行分类选择</p> 
                <el-form-item label="视频分类">
                    <el-select style="width: 36%" v-model="videoPassForm.cate_id" @change="getVal" placeholder="全部">
                            <el-option
                            v-for="item in dataItem"
                            :key="item.id"
                            :label="item.name"
                            :value="item.id">
                            </el-option>
                    </el-select>
                    <el-button type="text" @click="addKindTigger()">添加分类</el-button>
                </el-form-item>
                <el-form-item label="储存期限" style="height: 60px;">
                    <el-radio-group v-model="saveMonth" class="video-month">
                        <el-radio :label="1">永久保存</el-radio>
                        <el-radio :label="2">三个月</el-radio>
                        <el-radio :label="3">半年</el-radio>
                        <el-radio :label="4">一年</el-radio>
                        <el-radio :label="5">更多 
                            <el-input-number v-model="vals"
                            :min="13" :max="36" :controls="false" :precision="0" style="width: 58px">
                            </el-input-number> 月<span style="color: #999">（限制为13～36个月）</span>
                        </el-radio> 
                    </el-radio-group>
                </el-form-item>
		    </el-form>
            <span slot="footer" class="dialog-footer">
				<el-button @click="passActive()">取 消</el-button>
				<el-button type="primary"  @click="passActive(1)">确 定</el-button>
			</span>
		</el-dialog>
        <!-- 添加分类----------------------------------------------------- -->
		<el-dialog
		title="视频分类"
		:visible.sync="addKindFlag"
		:close-on-click-modal="false" 
        :close-on-press-escape="false"
		@close="handleClosed()"
		width="30%">
			<p>添加分类：
				<el-input type="text" style="width:220px;" @keyup.enter.native="addCategory" placeholder="输入视频分类，不超过8个字" v-model.trim="addKindForm.value" maxlength="8"> </el-input>
				<el-button type="primary" @click="addCategory()">添加</el-button>
			</p>
			<p style="padding-bottom:30px;">分类管理：<br>
				<el-tag size="mini" v-for="item in dataItem" :key="item.id" style="margin-top:5px;margin-right:3px;" @close.stop="delClose(item)" closable>{{ item.name }}</el-tag>
			</p>
		</el-dialog>
		<!-- 添加分类-------------------------------------------------------------------- -->
    </div>
</template>
<script>
    // import nativeVideo from '../../public/nativeVideo'
    import videoAlertView from '../../public/videoAlertView'
    export default {
    data() {
        return {
        saveMonth: 1,
        vals: 13,
        passID: '',
        addKindFlag: false, //添加分类弹窗状态
        dataItem: [], // 装视频分类的数据
        addKindForm: { // 添加视频分类
            value: '',  
        },
        videoPassFlag: false, // 控制审核通过弹窗 --多级
        videoPassForm: {
            cate_id: 0,
            month: 0,
        },
		schoolcodeData: [], /**存放学校教育局列表 */
        positionData:[], // 推首页使用
        tempPositionData:[], // 推首页使用
        homeVisible: false, // 推首页使用
        ruleForm: {
            selectIndex: null,
        },
        pushUpFlag: false, //推上级弹窗状态
        videoForm: {
            video_name: ''
        },
        rowLen: 0,
        platform_id: "",
        school_id: '',
        keyword: "",
        platformList: [],/*存放平台列表 */
        ids: [],/*存放被选中的视频列表 */
        loading: {
            status: false,
            txt: "获取数据..."
        },
        total_number: 0,
        listData: [],
        listParam: {
            type: '',
            platform_id: "",
            school_id: '',
            keyword: "",
            status: "",
            page_index: 1,
            page_size: 10
        },
        status: '',
        rejectWin: false,/*拒绝弹窗 */
        // rejectForm: {
        //     txt: '',/*拒绝理由填写 */
        // },
        rejectObj: null,/*拒绝对象 */
        isActive: true,
        home_flag:1,
        showVideoPlayer:false,
        playParam:{play_url:'', type: 'application/x-mpegURL'},
        rejectDescFlag: false,
        rejectDesc: '',
        };
    },
    created() {
        this.getList();
        this. get_schoolcode();
        if (Object.is(this.$store.state.platformInformation, 0)) {
        this.get_canseeposition();
        }
        this.findCategory();
    },
    methods: {
        // ---------------------------------------------------------新添加
        addKindTigger() { //控制添加分类弹窗
            this.addKindFlag = true
        },
        findCategory() {  // 获取视频分类
        const success = res => {
            this.dataItem = res.data
            this.dataItem.unshift({id: 0, name: '全部'})
        }
        this.$ajax.get('api/video/video_cate',{func:{success:success}})
        },
        handleClosed() {
            this.addKindForm.value = ''
        },
        addCategory() { // 添加视频分类
        if(this.addKindForm.value == '') {
            this.$message.error('内容不能为空')
            return
        }
        let params = {
            name: this.addKindForm.value,
        }
        const success=res=>{
            this.$message.success(res.msg);
            this.addKindForm.value = '';
            this.findCategory();
        }
        const fail = res => {
            this.$message.error(res.msg);
        }
        this.$ajax.post('api/video/video_cate',params,{func:{success:success, fail: fail}})
        },
        delClose(item) { // 删除视频分类
            let params = {
                id : item.id
            }
            this.dataItem.splice(this.dataItem.indexOf(item), 1);
            let success = res =>{
                this.$message.success(res.msg);
            }
            this.$ajax.delete('api/video/video_cate',{params,func:{success}})
        },
        // ---------------------------------------------------------新添加
        getVal(val){ // 获取当前选中项，
            this.videoPassForm.cate_id = val // 把获取到的分类id 给 添加视频的视频分类id字段
        },
        tableSelectionChange(val) { // 选框
        this.ids = [];
            if(val.length > 0) {
                val.forEach(item=>{
                this.ids.push(item.id);
                })
            }
        },
        checkValue(rule, value, callback) {
            if (!checkSpace(value)) {
            callback(new Error("请输入有效值"));
                    }else {
            callback();
            }
        },
        get_schoolcode(){ /*获取学校教育局 */
            let params = {
                app_code: sessionStorage.getItem('CheckSchoolAppCode')
            }
            let success = res => {
                // console.log(res, 'pppp')
                this.schoolcodeData = res.data
            }
            this.$ajax.get('api/group/get_platform_org', {params, func: {success}})
        },
        // 获取平台列表
        get_canseeposition() {
        const success = res => {
            // console.log(res, 300)
            this.platformList = res.data.data;
        };
        this.$ajax.get("api/level/get_canseeposition_school", {
            params: {},
            func: { success: success }
        });
        },
        getList() {
        this.loading.status = true;
        
        const success = res => {
            console.log(JSON.parse(JSON.stringify(res.data.data)), 1000)
            this.loading.status = false;
            this.listData = res.data.data;
            this.total_number = res.data.data_sum;
        };
        if(this.$store.state.checkLevel){
            this.$ajax.get("api/video/video_pushed_receive", {params: this.listParam,func: { success: success }});
        }else{
            this.$ajax.get("api/level/push_receive_list", {params: this.listParam,func: { success: success }})
        }
        },
        search() {
            if(this.$store.state.checkLevel){
                this.listParam.school_id = this.school_id
            }
            this.listParam.keyword = this.keyword;
            this.listParam.status = this.status;
            this.listParam.page_index = 1;
            this.listParam.page_size = 10;
            this.getList();
        },
        reset() {
            this.platform_id = '';
            this.school_id = '';
            this.keyword = '';
            this.status = '';
            this.listParam = {
                type: 0,
                platform_id: 0,
                keyword: "",
                status: "",
                page_index: 1,
                page_size: 10
            }
            this.getList();
        },
        
        handleSizeChange(size) {
        this.listParam.page_size = size;
        this.getList();
        },
        handleCurrentChange(page) {
        this.listParam.page_index = page;
        this.getList();
        },
        pass(id) {/*批准*/
            let params = {
                id: id,
            }
            const success = res=> {
                this.$message.success(res.msg);
                this.getList();
            }
            this.$ajax.post('api/level/approve_pushed_receive',params,{func:{success:success}})
        },
        passTrigger(data) {/*批准提示 */
            let tipsTxt = `确定批准${data.res_name}通过审核吗？`;
            this.$confirm(tipsTxt, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
            }).then(() => {
            this.pass(data.id)
            }).catch(() => {
            this.$message({
                type: 'info',
                message: '已取消批准'
            });          
            });
        },

        // 多级版---------------------------------------------------------
        videoPass(data) {/*批准*/  
            let params = {
                id: this.passID,
                cate_id: this.videoPassForm.cate_id,
                month: this.videoPassForm.month
            }
            const success = res=> {
                this.$message.success(res.msg);
                this.getList();
            }
            this.$ajax.post('api/video/video_pushed_receive',params,{func:{success:success}})
        },
        videoPassTrigger(data) {/*批准提示 */
            console.log(data.id)
            this.passID = data.id
            this.videoPassFlag = true
        },
        passActive(flag) {
            if(flag) {
                if(this.saveMonth === 1) {
                    this.videoPassForm.month = 0
                }else if(this.saveMonth === 2) {
                    this.videoPassForm.month = 3
                }else if(this.saveMonth === 3) {
                    this.videoPassForm.month = 6
                }else if(this.saveMonth === 4) {
                    this.videoPassForm.month = 12
                }else if(this.saveMonth === 5) {
                    this.videoPassForm.month = this.vals
                }
                
                this.videoPass();
                this.videoPassForm.cate_id = 0
                this.videoPassForm.month = 0
                this.videoPassFlag = false
            }else {
                this.videoPassForm.cate_id = 0
                this.videoPassForm.month = 0
                this.videoPassFlag = false
                return
            }
        },
        // 多级版---------------------------------------------------------

        rejectTrigger(data) {/*拒绝弹窗 */
            this.rejectWin = true;
            this.rejectObj = data;
        },
        rejectWinHide() {/*隐藏拒绝弹窗 */
            this.rejectWin = false;
            this.rejectObj = null;
            // this.rejectForm.txt = '';
        },
        reject() {/*拒绝 */
            let params = {
                id: this.rejectObj.id,
                // comment: this.rejectForm.txt,
            }
            const success = res=> {
                this.$message.success(res.msg);
                this.rejectWinHide();
                this.getList();
            }
            // this.$refs[`rejectForm`].validate(valid => {
            // if (valid) {
            // this.$ajax.put('api/level/refuse_pushed_receive',params,{func:{success:success}})
            this.$ajax.put('api/video/video_pushed_receive',params,{func:{success:success}})
            // } else {
            // return;
            // }
        // })
        },
        delTrigger(data) {/*删除提示 */
            let tipsTxt = `确认删除${data.name}吗？`;
            this.$confirm(tipsTxt, '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                    this.del(data.id)
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消删除'
                });          
            });
        },
        del(id) { // 删除单个----------------------
            let params = {
                id: id,
            }
            const success=res=>{
                this.$message.success(res.msg);
                this.getList();
            }
            this.$ajax.delete('api/video/video_pushed_receive',{params,func:{success:success}})
        },
        /**
         * 批量删除视频
         */
        deleteAll() {
            if (this.ids.length <= 0) {
                this.$message.warning("请选择要删除的视频");
                return false;
            }
            const cancel = (res => {})
            const yes = (res => {
                this.listData.forEach((item, index) =>{
                    this.ids.forEach((itm, idx) =>{
                        if(item.id == itm) {
                            this.deleteAllData(itm)
                        }
                    })
                })
            })

            this.e_confirm({yes, cancel, txt: "确定要删除选中的视频吗？"});
        },
        /**
         * 批量删除
         */
        deleteAllData(id){
            let params = {
                id: id
            }
            let success = (res => {
                this.$message.success(res.msg);
                this.getList();
            });
            this.$ajax.delete('api/video/video_pushed_receive', {params, func: {success: success}})
        },
        videoEdit(item){
            console.log(item, 999)
            if(item.videoInfo.status_m3u8==1){
                this.$router.push({path:'/resources/video/video-editing/'+item.new_res_id})
            }else{
                this.$message.warning("视频转码中，不可进行编辑");
            }
        },
        // 视频预览
        viewClose(){
            this.showVideoPlayer = false;
            this.isActive = true
        },
        videoView(obj){
            this.loading.status  = true;
            let success = (data=>{
                console.log(data)
                this.loading.status = false;
                this.playParam.play_url = data.data.play_url;
                this.showVideoPlayer = true;
                this.isActive = false
            })
            let fail = ( data => {
                this.loading.status = false
                this.$message.warning(data.msg)
            })
                //执行请求，并将回调方法变成config成员以便鉴权过期可以执行
            this.$ajax.get('api/video/check_view',{params: { id: obj.old_res_id },func:{success:success,fail:fail}})
    },
    down(id){ // 下载-----------------------------------
        var form = document.createElement("form");
        form.action = this.BASE_URL+'/index/resource/resourcedownload';
        form.method = 'post';
        form.style.display = "none";
        
        var opt_id = document.createElement("textarea");
        opt_id.name = 'id';
        opt_id.value = id;
        form.appendChild(opt_id);
        var opt_type = document.createElement("textarea");
        opt_type.name = 'type';
        opt_type.value = 0;
        form.appendChild(opt_type);
        document.body.appendChild(form);
        form.submit();
        document.body.removeChild(form);
    },
    /**
     * 推首页-----------------------------------------------------------
     */
    pushToTop(){  // 首页置顶
        var newTemp = [];
            newTemp.push( deep_clone( this.pushObj ) );
        var temp_  = { id:null , position: null , name:'' , picture: '/static/default/video_cover.png'}
        var have_continued = false;//是否已经跳过第一个空的推首页项
        //去掉在里面的当前的推首页项
        for (var i = this.positionData.length - 1; i >= 0; i--) {
            if( parseInt( this.pushObj.resid ) === parseInt( this.positionData[i].resid ) ){
                this.positionData[i] =  deep_clone( temp_ );
                break;
            }
        }
        for ( var i = 0; i <= 7; i++ ) {
            //第一个空的推首页项,往后空的就不会跳过
            if( is_empty( this.positionData[i].id  ) && !have_continued ){
                have_continued  = true;
                continue;
            }
            newTemp.push( deep_clone( this.positionData[i] )  );
            if( newTemp.length === 8 ){
                break;
            }

        } 
        this.home_flag = 0 ;
        this.ruleForm.selectIndex = 0;
        this.positionData = deep_clone( newTemp );          
    },
    savePosition(){
        let success = ( data=>{
            this.$message.success(data.msg);
            this.homeVisible = false;
        })
        var params = {
            id : [],
            position : [],
            resid : this.pushObj.resid,
            home_flag : this.home_flag,
        };
        for ( var i = 0; i < this.positionData.length; i++ ) {
            if( !is_empty( this.positionData[i].resid ) ){
                params.id.push( this.positionData[i].resid );
                params.position.push( i+1 );
            }else{
                params.id.push( null );
                params.position.push( null );
            }
        }
        this.$ajax.post('api/video/push_to_home',params,{func:{success:success}})
        
    },
    getPosition(){
        this.loading.status = true;
        let success = (data=>{
            this.loading.status = false;
            this.tempPositionData = data.data;
            this.ruleForm.selectIndex = null;
            this.renderPushHtml();
        })
        let fail = ( data => {
            this.loading.status = false;
            this.$message.error(data.msg)
        })
        //执行请求，并将回调方法变成config成员以便鉴权过期可以执行
        this.$ajax.get('api/video/video_home_position',{func:{success:success,fail:fail}})
    },
    renderPushHtml(){
        this.positionData = [];
        for (var i = 0; i <= 7; i++) {
            var temp_  = { id:null, position: i+1 , name:'' , picture: '/static/default/video_cover.png'}
            for ( var j = 0 ; j < this.tempPositionData.length; j++ ) {
                if( (i+1) === parseInt( this.tempPositionData[j].position )  ){
                    if( is_empty(this.ruleForm.selectIndex) || ( !is_empty(this.ruleForm.selectIndex) && parseInt(this.pushObj.resid) !== parseInt( this.tempPositionData[j].resid )  )){
                        temp_ = deep_clone(this.tempPositionData[j]);
                    }
                    
                }
            }
            if( this.ruleForm.selectIndex === i ){
                this.positionData.push(  this.pushObj );
            }else{
                this.positionData.push( temp_ );
            }
            
        }
        //取消首页置顶
        if( this.home_flag === 0 && this.ruleForm.selectIndex !== 0 ){
            this.home_flag = 1;
        }
        
    },
    pushIndexBox(obj){ // 推首页----------------------
        this.homeVisible = true;
        this.ruleForm.selectIndex = null;
        this.pushObj = {resid:obj.new_res_id,name:obj.name,picture:obj.videoInfo.picture,position:null,study_section_id:obj.videoInfo.study_section_id,grade_id:obj.videoInfo.grade_id}
        this.getPosition();
    },
    deletePushIndex(inx){
        this.positionData[inx].id = null;
        this.positionData[inx].position = null;
        this.positionData[inx].name = '';
        this.positionData[inx].picture = '/static/default/video_cover.png'
        var deletet_inx =  -1;
        this.tempPositionData.forEach( (item ,inxx) =>{
            if(parseInt(item.position)-1 === inx ){
                deletet_inx = inxx;
            }
        })
        deletet_inx > -1 && this.tempPositionData.splice( deletet_inx )
    },
    submitForm(formName) {
        this.$refs[formName].validate((valid) => {
            if (valid) {
                this.savePosition();
            } else {
                return false;
            }
        });
    },
    resetForm(formName) {
        this.$refs[formName].resetFields();
        this.ruleForm.selectIndex = null;
        this.getPosition();
    },
    /**
     * 推首页-----------------------------------------------------------
     */
    pushUpTrigger(data) { // 推上级---------------------------
        this.video_id = data.new_res_id
        this.videoForm = {
            video_name: data.name
        }
        this.pushUpFlag = true
    },
    pushUpTips(flag) {
        if(flag) {
            /*确定的逻辑 */
            this.pushUp(this.video_id)
            this.pushUpFlag = false
        } else {
            this.pushUpFlag = false
            return
        }
    },
    pushUp(video_id) {
        let params = {
            video_id: video_id
        }
        let success = res =>{
            this.$message.success(res.msg)
            this.getList();
        }
        this.$ajax.post('api/video/video_push', params, {func: {success: success}})
    },
    // 推上级---------------------------
    checkReject(data) {
        this.rejectDescFlag = true;
        this.rejectDesc = data.comment;
    },
    },
    components: {
        videoAlertView,
        // nativeVideo

    }
    };
</script>
<style lang="scss">
    .video-check {
        .video-month {
            height: 30px;
            line-height: 30px;
        }
        .page-checked{
			width: 177px;
			height: 150px;
			overflow: hidden;
			margin-right: 10px !important ;
			padding: 0;
			&:nth-of-type(4n){
				margin-right: 0 !important ;
			}
			.el-radio__input{
				position: absolute;
				bottom: 10px;
				left: 0;
			}
			.home-page-ls{
				>div{
					position: relative;
					width: 100%;
					height: 100px;
					overflow: hidden;
					margin-bottom: 10px;
					>img{
						width: 100%;
						height: 100%;
                        object-fit: cover;
					}
					>i {
						position: absolute;
						right: 5px;
						top: 5px;
						// color: #348efc;
					}
				}
				>p{
					margin: 0;
					padding-left: 20px;
				}
			}
		}
        .textarea-box {
            position: relative;
            .el-textarea__inner {
            min-height: 120px !important;
            resize: none;
            }
            .str-num {
            position: absolute;
            padding: 0;
            margin: 0;
            left: 0;
            bottom: 5px;
            right: 15px;
            text-align: right;
            .str-max {
                color: #ddd;
            }
            }
        }
        .masking{
            display: block;
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            transition: .5s;
            background: rgba(0,0,0,.3);
            z-index: 4;
            .maskingBox{
                position: absolute;
                top: 20%;
                left: 50%;
                width: 800px;
                margin-left: -400px;
                background: #fff;
            }
            .masking_h{
                padding: 10px 15px;
                background: #348EFC;
                text-align: center;
                text-align-last: justify;
                >span,
                >i{
                    font-size: 16px;
                    text-align-last: initial;
                    display: inline-block;
                    vertical-align: middle;
                    color: #fff;
                }
                >i{
                    cursor: pointer;
                }
            }
            .masking_c{
                padding: 30px;
            }

        }

        .activeLive{
            opacity: 0;
            visibility: hidden;
        }
        .videPAHT{
            color: #409EFF;
            margin-right: 10px;
        }
    }
</style>

